package com.service;
import static com.def.GenericDef.ACTION_FLG_ADD;
import static com.def.GenericDef.ACTION_FLG_DELETE;
import static com.def.GenericDef.ACTION_FLG_INQUIRE;
import static com.def.GenericDef.ACTION_FLG_QUERY;
import static com.def.GenericDef.ACTION_FLG_UPDATE;
import static com.def.GenericDef.ACTION_FLG_REPLACE;
import static com.def.GenericDef.E_SPCCHTMN_ALREDY_EXIST;
import static com.def.GenericDef.E_SPCCHTMN_NOT_FOUND_RECORD;
import static com.def.GenericDef.RETURN_CODE_OK;
import static com.def.GenericDef.RETURN_CODE_UNKNOWN;
import static com.def.GenericDef.RETURN_MESG_OK;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.dao.ISpcBisChartMainDao;
import com.dao.ISpcRetChartInfoDao;
import com.icim.service.ICIMBaseService;
import com.model.Spc_bis_chart_main;
import com.model.Spc_bis_chart_mainId;
import com.model.Spc_ret_chart_info;
import com.model.Spc_ret_chart_infoId;
import com.tx.Spcchtmn.SpcchtmnI;
import com.tx.Spcchtmn.SpcchtmnIA;
import com.tx.Spcchtmn.SpcchtmnIB;
import com.tx.Spcchtmn.SpcchtmnO;
import com.tx.Spcchtmn.SpcchtmnOA;
import com.tx.Spcchtmn.SpcchtmnOB;
import com.util.MqOpe;
import com.util.Util;

@Scope("prototype")
@Service("SpcchartmainService")
public class SpcchartmainService extends ICIMBaseService{
	
	private Logger logger = Logger.getLogger(SpcchartmainService.class);
	@Autowired
	private SpcchtmnI spcchtmnI;
	
	@Autowired
	private SpcchtmnO outTrx; 
	
	@Autowired
	private ISpcBisChartMainDao spcBisChartMainDao;
	
	@Autowired
	private ISpcRetChartInfoDao spcRetChartInfoDao;
	
	@Autowired
	private MqOpe mqOpe;
	public String subMainProc(String strInMsg){
		logger.info("InTrx is "+ strInMsg );
		try{
			outTrx.setTrx_id("SPCGRPMN");
			outTrx.setType_id("O");
			spcchtmnI = (SpcchtmnI) mqOpe.inStr2Obj(strInMsg,spcchtmnI);
			char action_flg = spcchtmnI.getAction_flg().charAt(0);
			switch( action_flg ){
				case ACTION_FLG_QUERY   :  queryByCondition()  ; break;   
				case ACTION_FLG_ADD     :  addFnc()            ; break;
				case ACTION_FLG_UPDATE  :  updateFnc()         ; break;
				case ACTION_FLG_DELETE  :  deleteFnc()         ; break;
				case ACTION_FLG_INQUIRE :  inquireChartSettingFnc();break;
				case ACTION_FLG_REPLACE :  updateChartSettingFnc();break;
				default                 :  errActionFnc();   
			}
			if( RETURN_CODE_OK.equals(outTrx.getRtn_code()) ){
				spcRetChartInfoDao.flushCurSession();
				outTrx.setRtn_mesg(RETURN_MESG_OK);
			}else{
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			}
		}catch(Exception ex){
			outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
			outTrx.setRtn_mesg(ex.toString());
			logger.error(Util.stackTraceToString(ex));
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}finally{
			logger.info(mqOpe.obj2Str(outTrx));
		}
		return mqOpe.obj2Str(outTrx);
	}
	
	public void addFnc()  {
		SpcchtmnIA iary = spcchtmnI.getIary().get(0);
		String col_typ_fk = iary.getCol_typ_fk();
		String grp_no_fk  = iary.getGrp_no_fk();
		String dataGroup = iary.getData_group_fk();
		
		
		
//		boolean isExisted = checkDataGroupExist(col_typ_fk, grp_no_fk, dataGroup);
//		if(isExisted){
//			outTrx.setRtn_code(E_SPCCHTMN_ALREDY_EXIST+"");
//			outTrx.setRtn_mesg("一个group下面不允许存在量测名称相同的两张管制图");
//			return ;
//		}
		
		String hql ="FROM Spc_bis_chart_main where id.col_typ_fk='" + iary.getCol_typ_fk() +
		            "' and id.grp_no_fk='"+iary.getGrp_no_fk()+
		            "' and chart_name='"+iary.getChart_name() +"'";
		List<Spc_bis_chart_main> spc_bis_chart_mainList = spcBisChartMainDao.find(hql);
		if(spc_bis_chart_mainList!=null && spc_bis_chart_mainList.size()!=0){
			outTrx.setRtn_code(E_SPCCHTMN_ALREDY_EXIST+"");
			outTrx.setRtn_mesg("chart["+iary.getChart_name()+"]"+"already Exist,please Check");
			return ;
		}
		String chart_no = getMaxChartNoFnc(col_typ_fk,grp_no_fk);
		Spc_bis_chart_mainId chartMainId = new Spc_bis_chart_mainId();
		chartMainId.setCol_typ_fk(col_typ_fk);
		chartMainId.setGrp_no_fk(grp_no_fk);
		chartMainId.setChart_no(chart_no);
		Spc_bis_chart_main spc_bis_chart_main = new Spc_bis_chart_main();
		spc_bis_chart_main.setId(chartMainId);
		spc_bis_chart_main.setChart_typ(iary.getChart_typ());
		
		spc_bis_chart_main.setData_group_fk(dataGroup);
		spc_bis_chart_main.setChart_name(iary.getChart_name());
		spc_bis_chart_main.setChart_dsc(iary.getChart_dsc());
		spc_bis_chart_main.setChart_owner(iary.getChart_owner());
		spc_bis_chart_main.setChart_sub_typ(iary.getChart_sub_typ());
		spc_bis_chart_main.setMax_chart_point(iary.getMax_chart_point());
		spc_bis_chart_main.setEvt_usr(iary.getEvt_usr());
		spc_bis_chart_main.setEvt_timestamp(Util.getCurrentTimestamp());
//		spc_bis_chart_main.setOoc_ocap(iary.getOoc_ocap());
//		spc_bis_chart_main.setOos_ocap(iary.getOos_ocap());
		spc_bis_chart_main.setRaw_keep_flg(iary.getRaw_keep_flg());
		spc_bis_chart_main.setSample_size(iary.getSample_size());
		spcBisChartMainDao.save(spc_bis_chart_main);
		
		List<SpcchtmnIB> iaryBList = spcchtmnI.getIaryB();
		if(iaryBList==null){
			outTrx.setRtn_code(RETURN_CODE_OK);
			return ;
		}
		for(SpcchtmnIB iaryB : iaryBList){
			Spc_ret_chart_info spc_ret_chart_info = new Spc_ret_chart_info();
			Spc_ret_chart_infoId chart_infoId = new Spc_ret_chart_infoId();
			chart_infoId.setCol_typ_fk(col_typ_fk);
			chart_infoId.setGrp_no_fk(grp_no_fk);
			chart_infoId.setChart_no_fk(chart_no);
			chart_infoId.setChart_typ_fk(iaryB.getChart_typ_fk());
			spc_ret_chart_info.setId(chart_infoId);
			spc_ret_chart_info.setData_group_fk(iaryB.getData_group_fk());
//			spc_ret_chart_info.setChart_ual(iaryB.getChart_ual());
			spc_ret_chart_info.setChart_ucl(iaryB.getChart_ucl());
			spc_ret_chart_info.setChart_upl(iaryB.getChart_upl());
			spc_ret_chart_info.setChart_usl(iaryB.getChart_usl());
//			spc_ret_chart_info.setChart_uwl(iaryB.getChart_uwl());
			spc_ret_chart_info.setChart_mean(iaryB.getChart_target());
			spc_ret_chart_info.setChart_target(iaryB.getChart_target());
//			spc_ret_chart_info.setChart_lal(iaryB.getChart_lal());
			spc_ret_chart_info.setChart_lcl(iaryB.getChart_lcl());
			spc_ret_chart_info.setChart_lpl(iaryB.getChart_lpl());
			spc_ret_chart_info.setChart_lsl(iaryB.getChart_lsl());
//			spc_ret_chart_info.setChart_lwl(iaryB.getChart_lwl());
			spc_ret_chart_info.setChart_rule_1_info(iaryB.getChart_rule_1_info());
			spc_ret_chart_info.setChart_rule_1_action(iaryB.getChart_rule_1_action());
			spc_ret_chart_info.setChart_rule_1_param(iaryB.getChart_rule_1_param());
			spc_ret_chart_info.setChart_rule_2_info(iaryB.getChart_rule_2_info());
			spc_ret_chart_info.setChart_rule_2_action(iaryB.getChart_rule_2_action());
			spc_ret_chart_info.setChart_rule_2_param(iaryB.getChart_rule_2_param());
			spc_ret_chart_info.setChart_spec_chk_flg(iaryB.getChart_spec_chk_flg());
			spc_ret_chart_info.setChart_show_multi_power(iaryB.getChart_show_multi_power());
			spc_ret_chart_info.setChart_ack_flg(iaryB.getChart_ack_flg());
			spcRetChartInfoDao.save(spc_ret_chart_info);
		}
	
		List<SpcchtmnOA> oaryList = new ArrayList<SpcchtmnOA>();
		SpcchtmnOA oary = new SpcchtmnOA();
		
		oary.setCol_typ_fk(spc_bis_chart_main.getId().getCol_typ_fk());
		oary.setGrp_no_fk(spc_bis_chart_main.getId().getGrp_no_fk());
		oary.setChart_no(spc_bis_chart_main.getId().getChart_no());
		oary.setChart_name(spc_bis_chart_main.getChart_name());
		oary.setChart_dsc(spc_bis_chart_main.getChart_dsc());
		oary.setChart_owner(spc_bis_chart_main.getChart_owner());
		oary.setChart_typ(spc_bis_chart_main.getChart_typ());
		oary.setData_group_fk(spc_bis_chart_main.getData_group_fk());
		oary.setSample_size(spc_bis_chart_main.getSample_size());
		oary.setMax_chart_point(spc_bis_chart_main.getMax_chart_point());
		oary.setRaw_keep_flg(spc_bis_chart_main.getRaw_keep_flg());
		oary.setChart_sub_typ(spc_bis_chart_main.getChart_sub_typ());
		oaryList.add(oary);
		
		outTrx.setOary(oaryList);
		outTrx.setRtn_code(RETURN_CODE_OK);
		
	}

//	private boolean checkDataGroupExist(String col_typ_fk, String grp_no_fk, String dataGroup) {
//		String checkHql ="FROM Spc_bis_chart_main where id.col_typ_fk= ? and id.grp_no_fk= ? and data_group_fk = ? ";
//		List<Spc_bis_chart_main> list = spcBisChartMainDao.list(checkHql, col_typ_fk,grp_no_fk,dataGroup);
//		if(!list.isEmpty()){
//			return true;
//		}
//		return false;
//	}
	public void updateFnc(){
		SpcchtmnIA iary = spcchtmnI.getIary().get(0);
		String col_typ_fk = iary.getCol_typ_fk();
		String grp_no_fk  = iary.getGrp_no_fk();
		String chart_no   = iary.getChart_no();
		String dataGroup = iary.getData_group_fk();
		Spc_bis_chart_mainId chartMainId = new Spc_bis_chart_mainId();
		chartMainId.setCol_typ_fk(col_typ_fk);
		chartMainId.setGrp_no_fk(grp_no_fk);
		chartMainId.setChart_no(chart_no);
		
		
		
		Spc_bis_chart_main spc_bis_chart_main = spcBisChartMainDao.get(chartMainId);
		if( spc_bis_chart_main == null){
			outTrx.setRtn_code(E_SPCCHTMN_NOT_FOUND_RECORD+"");
			outTrx.setRtn_mesg("chart["+iary.getChart_name()+"]"+"not found,please Check");
			return ;
		}
//		spc_bis_chart_main.setChart_typ(iary.getChart_typ());
		if(iary.getChart_name()!=null){
			spc_bis_chart_main.setChart_name(iary.getChart_name());
		}
		if(iary.getChart_dsc()!=null){
			spc_bis_chart_main.setChart_dsc(iary.getChart_dsc());
		}
		if(iary.getChart_owner()!=null){
			spc_bis_chart_main.setChart_owner(iary.getChart_owner());
		}
		if(iary.getMax_chart_point()!=null){
			spc_bis_chart_main.setMax_chart_point(iary.getMax_chart_point());
		}
		if(iary.getRaw_keep_flg()!=null){
			spc_bis_chart_main.setRaw_keep_flg(iary.getRaw_keep_flg());
		}
		if(iary.getSample_size()!=null){
			spc_bis_chart_main.setSample_size(iary.getSample_size());
		}
		
		spc_bis_chart_main.setEvt_usr(iary.getEvt_usr());
		spc_bis_chart_main.setEvt_timestamp(Util.getCurrentTimestamp());
//		spc_bis_chart_main.setOoc_ocap(iary.getOoc_ocap());
//		spc_bis_chart_main.setOos_ocap(iary.getOos_ocap());
		spcBisChartMainDao.update(spc_bis_chart_main);
		
		List<SpcchtmnIB> iaryBList = spcchtmnI.getIaryB();
		if(iaryBList==null){
			outTrx.setRtn_code(RETURN_CODE_OK);
			return ;
		}
		for(SpcchtmnIB iaryB : iaryBList){
			
			Spc_ret_chart_infoId chart_infoId = new Spc_ret_chart_infoId();
			chart_infoId.setCol_typ_fk(col_typ_fk);
			chart_infoId.setGrp_no_fk(grp_no_fk);
			chart_infoId.setChart_no_fk(chart_no);
			chart_infoId.setChart_typ_fk(iaryB.getChart_typ_fk());
			Spc_ret_chart_info spc_ret_chart_info = spcRetChartInfoDao.get(chart_infoId);
			spc_ret_chart_info.setId(chart_infoId);
//			spc_ret_chart_info.setChart_ual(iaryB.getChart_ual());
			spc_ret_chart_info.setChart_ucl(iaryB.getChart_ucl());
			spc_ret_chart_info.setChart_upl(iaryB.getChart_upl());
			spc_ret_chart_info.setChart_usl(iaryB.getChart_usl());
//			spc_ret_chart_info.setChart_uwl(iaryB.getChart_uwl());
			spc_ret_chart_info.setChart_mean(iaryB.getChart_target());
			spc_ret_chart_info.setChart_target(iaryB.getChart_target());
//			spc_ret_chart_info.setChart_lal(iaryB.getChart_lal());
			spc_ret_chart_info.setChart_lcl(iaryB.getChart_lcl());
			spc_ret_chart_info.setChart_lpl(iaryB.getChart_lpl());
			spc_ret_chart_info.setChart_lsl(iaryB.getChart_lsl());
//			spc_ret_chart_info.setChart_lwl(iaryB.getChart_lwl());
			spc_ret_chart_info.setChart_rule_1_info(iaryB.getChart_rule_1_info());
			spc_ret_chart_info.setChart_rule_1_action(iaryB.getChart_rule_1_action());
			spc_ret_chart_info.setChart_rule_1_param(iaryB.getChart_rule_1_param());
			spc_ret_chart_info.setChart_rule_2_info(iaryB.getChart_rule_2_info());
			spc_ret_chart_info.setChart_rule_2_action(iaryB.getChart_rule_2_action());
			spc_ret_chart_info.setChart_rule_2_param(iaryB.getChart_rule_2_param());
			spc_ret_chart_info.setChart_spec_chk_flg(iaryB.getChart_spec_chk_flg());
			spc_ret_chart_info.setChart_show_multi_power(iaryB.getChart_show_multi_power());
			spc_ret_chart_info.setChart_ack_flg(iaryB.getChart_ack_flg());
			spcRetChartInfoDao.saveOrUpdate(spc_ret_chart_info);
		}
		outTrx.setRtn_code(RETURN_CODE_OK);
	}
	public void deleteFnc(){
		List<SpcchtmnIA> iaryList = spcchtmnI.getIary();
		for(SpcchtmnIA iary: iaryList){
			Spc_bis_chart_mainId chartMainId = new Spc_bis_chart_mainId();
			chartMainId.setCol_typ_fk(iary.getCol_typ_fk());
			chartMainId.setGrp_no_fk(iary.getGrp_no_fk());
			chartMainId.setChart_no(iary.getChart_no());
			Spc_bis_chart_main spc_bis_chart_main = spcBisChartMainDao.get(chartMainId);
			if(spc_bis_chart_main==null){
				outTrx.setRtn_code(E_SPCCHTMN_NOT_FOUND_RECORD+"");
				outTrx.setRtn_mesg("not found main group");
				return ;
			}
			spcBisChartMainDao.delete(spc_bis_chart_main);
			String hql = "FROM Spc_ret_chart_info where id.col_typ_fk='" +iary.getCol_typ_fk() +
		      "' and id.grp_no_fk='"+ iary.getGrp_no_fk() +
		      "' AND id.chart_no_fk='"+ iary.getChart_no()+"'"; 
			List<Spc_ret_chart_info> spcRetChartInfoList = spcRetChartInfoDao.find(hql);
			for(Spc_ret_chart_info spc_ret_chart_info:spcRetChartInfoList){
				spcRetChartInfoDao.delete(spc_ret_chart_info);
			}
		}
		outTrx.setRtn_code(RETURN_CODE_OK);
	}
	public void queryByCondition(){
		String hql = "FROM Spc_bis_chart_main where 1=1" ;
		SpcchtmnIA iary = spcchtmnI.getIary().get(0);
		if(iary.getCol_typ_fk()!=null){
			hql = hql +" and id.col_typ_fk='" +iary.getCol_typ_fk() +"'";
		}
		if(iary.getGrp_no_fk()!=null){
			hql = hql +" and id.grp_no_fk='" +iary.getGrp_no_fk() +"'";
		}
		if(iary.getChart_no()!=null){
			hql = hql +" and id.chart_no='" +iary.getChart_no() +"'";
		}
		if(iary.getData_group_fk()!=null){
			hql = hql +" and data_group_fk='" +iary.getData_group_fk() +"'";
		}
		List<Spc_bis_chart_main> spcBisChartMainList = spcBisChartMainDao.find(hql);
		List<SpcchtmnOA> oaryList = new ArrayList<SpcchtmnOA>();
		for(Spc_bis_chart_main spc_bis_chart_main :spcBisChartMainList){
			SpcchtmnOA oary = new SpcchtmnOA();
			oary.setCol_typ_fk(spc_bis_chart_main.getId().getCol_typ_fk());
			oary.setGrp_no_fk(spc_bis_chart_main.getId().getGrp_no_fk());
			oary.setChart_no(spc_bis_chart_main.getId().getChart_no());
			oary.setData_group_fk(spc_bis_chart_main.getData_group_fk());
			oary.setChart_name(spc_bis_chart_main.getChart_name());
			oary.setChart_dsc(spc_bis_chart_main.getChart_dsc());
			oary.setChart_owner(spc_bis_chart_main.getChart_owner());
			oary.setChart_typ(spc_bis_chart_main.getChart_typ());
			oary.setChart_sub_typ(spc_bis_chart_main.getChart_sub_typ());
			oary.setEvt_usr(spc_bis_chart_main.getEvt_usr());
			oary.setEvt_timestamp(spc_bis_chart_main.getEvt_timestamp());
			oary.setMax_chart_point(spc_bis_chart_main.getMax_chart_point());
			oary.setOos_ocap(spc_bis_chart_main.getOos_ocap());
			oary.setOoc_ocap(spc_bis_chart_main.getOoc_ocap());
			oary.setRaw_keep_flg(spc_bis_chart_main.getRaw_keep_flg());
			oary.setSample_size(spc_bis_chart_main.getSample_size());
			oaryList.add(oary);
		}
		outTrx.setOary(oaryList);
		outTrx.setTbl_cnt(oaryList.size());
		outTrx.setRtn_code(RETURN_CODE_OK);
	}
	public void inquireChartSettingFnc(){
		String hql = "FROM Spc_ret_chart_info where 1=1" ;
		SpcchtmnIA iary = spcchtmnI.getIary().get(0);//.getIaryB().get(index);
		if(iary.getCol_typ_fk()!=null){
			hql = hql +" and id.col_typ_fk='" +iary.getCol_typ_fk() +"'";
		}
		if(iary.getGrp_no_fk()!=null){
			hql = hql +" and id.grp_no_fk='" +iary.getGrp_no_fk() +"'";
		}
		if(iary.getChart_no()!=null){
			hql = hql +" and id.chart_no_fk='" +iary.getChart_no() +"'";
		}
		if(iary.getChart_typ()!=null){
			hql = hql +" and id.chart_typ_fk='"+iary.getChart_typ()+"'";
		}
		hql =  hql + " order by id.chart_typ_fk";
		List<Spc_ret_chart_info> spcRetChartInfoList = spcRetChartInfoDao.find(hql);
		List<SpcchtmnOB> oaryBList = new ArrayList<SpcchtmnOB>();
		for(Spc_ret_chart_info spc_ret_chart_info:spcRetChartInfoList){
			SpcchtmnOB oaryB = new SpcchtmnOB();
			oaryB.setCol_typ_fk(spc_ret_chart_info.getId().getCol_typ_fk());
			oaryB.setGrp_no_fk(spc_ret_chart_info.getId().getGrp_no_fk());
			oaryB.setChart_no_fk(spc_ret_chart_info.getId().getChart_no_fk());
			oaryB.setChart_typ_fk(spc_ret_chart_info.getId().getChart_typ_fk());
			oaryB.setChart_spec_chk_flg(spc_ret_chart_info.getChart_spec_chk_flg());
			oaryB.setChart_rule_1_action(spc_ret_chart_info.getChart_rule_1_action());
			oaryB.setChart_rule_1_info(spc_ret_chart_info.getChart_rule_1_info());
			oaryB.setChart_rule_1_param(spc_ret_chart_info.getChart_rule_1_param());
			oaryB.setChart_rule_2_action(spc_ret_chart_info.getChart_rule_2_action());
			oaryB.setChart_rule_2_info(spc_ret_chart_info.getChart_rule_2_info());
			oaryB.setChart_rule_2_param(spc_ret_chart_info.getChart_rule_2_param());
			oaryB.setChart_calc_multi_power(spc_ret_chart_info.getChart_calc_multi_power());//倍率
			
//			oaryB.setChart_lal(spc_ret_chart_info.getChart_lal());
			oaryB.setChart_lcl(spc_ret_chart_info.getChart_lcl());
			oaryB.setChart_lpl(spc_ret_chart_info.getChart_lpl());
			oaryB.setChart_lsl(spc_ret_chart_info.getChart_lsl());
//			oaryB.setChart_lwl(spc_ret_chart_info.getChart_lwl());
			oaryB.setChart_mean(spc_ret_chart_info.getChart_mean());
			oaryB.setChart_target(spc_ret_chart_info.getChart_target());
//			oaryB.setChart_ual(spc_ret_chart_info.getChart_ual());
			oaryB.setChart_ucl(spc_ret_chart_info.getChart_ucl());
			oaryB.setChart_upl(spc_ret_chart_info.getChart_upl());
			oaryB.setChart_usl(spc_ret_chart_info.getChart_usl());
			oaryB.setChart_rule_1_info(spc_ret_chart_info.getChart_rule_1_info());
			oaryB.setChart_rule_1_action(spc_ret_chart_info.getChart_rule_1_action());
			oaryB.setChart_rule_1_param(spc_ret_chart_info.getChart_rule_1_param());
			oaryB.setChart_rule_1_rlt(spc_ret_chart_info.getChart_rule_1_rlt());
			oaryB.setChart_ack_flg(spc_ret_chart_info.getChart_ack_flg());
//			oaryB.setChart_uwl(spc_ret_chart_info.getChart_uwl());
			oaryBList.add(oaryB);
		}
		outTrx.setOaryB(oaryBList);
		outTrx.setTbl_cnt(oaryBList.size());
		outTrx.setRtn_code(RETURN_CODE_OK);
	}   
	
	public void updateChartSettingFnc() {
		List<SpcchtmnIB> iaryBList = spcchtmnI.getIaryB();
		for (SpcchtmnIB iaryB : iaryBList) {
			String colTyp = iaryB.getCol_typ_fk();
			String grpNo = iaryB.getGrp_no_fk();
			String chartNo  = iaryB.getChart_no_fk();
			String chartTyp = iaryB.getChart_typ_fk();
			String chartRule = iaryB.getChart_rule_1_info();
			String hql = "from Spc_ret_chart_info where col_typ_fk = ? and grp_no_fk=? and chart_no_fk = ? and chart_typ_fk = ?";
			Spc_ret_chart_info spcRetChartInfo = spcRetChartInfoDao.uniqueResultWithLock(hql, colTyp,grpNo,chartNo,chartTyp);
			spcRetChartInfo.setChart_rule_1_info(chartRule);
			spcRetChartInfoDao.save(spcRetChartInfo);
		}
		
		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
	}
	public void errActionFnc(){
		outTrx.setRtn_code("0000009");
		outTrx.setRtn_mesg("Invalid Action_flg");
	}
	public String getMaxChartNoFnc(String col_typ_fk,String grp_no_fk){
		String hql = "select max(id.chart_no) FROM Spc_bis_chart_main WHERE id.col_typ_fk='"+col_typ_fk+"'";
			   hql = hql + " and id.grp_no_fk='"+ grp_no_fk +"'";
	    Session session = spcBisChartMainDao.getCrSession();
		Query getMaxquery  = session.createQuery(hql);
		Object object = getMaxquery.uniqueResult();
		int iMaxChartNo=0;
		if(object!=null){
			iMaxChartNo = Integer.valueOf(object.toString());
    		return Util.comInt2String(iMaxChartNo+1,6);
		}
		return "000001";
	}
	
}


